package com.sk.waste.app.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.viewpager.widget.ViewPager;

public class SKViewPager extends ViewPager
  {
    public SKViewPager(Context context)
      {
        super(context);
      }

    public SKViewPager(Context context, AttributeSet attrs)
      {
        super(context, attrs);
      }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev)
      {
        boolean intercepted = super.onInterceptTouchEvent(reverseMotionEvent(ev));
        reverseMotionEvent(ev);
        return intercepted;
      }

    @Override
    public boolean onTouchEvent(MotionEvent ev)
      {
        boolean handled = super.onTouchEvent(reverseMotionEvent(ev));
        reverseMotionEvent(ev);
        return handled;
      }

    private MotionEvent reverseMotionEvent(MotionEvent ev)
      {
        float width = getWidth();
        float x = ev.getX();
        ev.setLocation(width - x, ev.getY());
        return ev;
      }
  }
